<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Amber - Pet Care Bootstrap 5 Template</title>

    <!-- Favicons -->
    <link rel="shortcut icon" href="assets/images/favicon.ico">
    <link rel="stylesheet" href="assets/css/vendor/vendor.min.css">
    <link rel="stylesheet" href="assets/css/plugins/plugins.min.css">
    <link rel="stylesheet" href="assets/css/style.min.css">
	
	<script src="static/regutils.js"></script>
	<script src="assets/jquery-3.6.0.min.js"></script>
	<script type="text/javascript">
		<!-- 导航栏的JS-开始 -->
		var itemHost = "http://localhost:3001/itemservice"
		//文档就绪
		$(function(){
			getItemCat();
		})
		//获取二级分类菜单，循环遍历添加菜单
		function getItemCat(){
			$.ajax({
				type:"get",
				url: itemHost + "/itemCat/getAll",
				success: function(result){
					if(result.status == 200){
						//console.log(result.data)
						var itemCatList = result.data
						//遍历一级分类菜单
						for(var i in itemCatList){
							var itemCatOne = itemCatList[i]
							var itemCatOneChildren = itemCatOne.children
							//遍历二级分类菜单
							if(i==0){
								for(var j in itemCatOneChildren){
									var itemCatTwo = itemCatOneChildren[j]
									$("#dog").append(
										`
											<li><a class="a" onclick="dogItem(${itemCatTwo.id})">${itemCatTwo.name}</a></li>
										`
									)
								}
							}
							if(i==1){
								for(var j in itemCatOneChildren){
									var itemCatTwo = itemCatOneChildren[j]
									$("#cat").append(
										`
											<li><a class="a" onclick="catItem(${itemCatTwo.id})">${itemCatTwo.name}</a></li>
										`
									)
								}
							}
							if(i==2){
								for(var j in itemCatOneChildren){
									var itemCatTwo = itemCatOneChildren[j]
									$("#other").append(
										`
											<li><a class="a" onclick="otherItem(${itemCatTwo.id})">${itemCatTwo.name}</a></li>
										`
									)
								}
							}
						}
					}					
				}
			})
		}
		//点击狗狗分类的某一个二级菜单，会获取item表中item_cat_id为此id的商品，并显示在shop.html页面
		function dogItem(id){
			$.ajax(itemHost+`/item/getData/${id}`)
			window.location.href="shop.html"
		}
		//点击猫咪分类的某一个二级菜单，会获取item表中item_cat_id为此id的商品，并显示在shop.html页面
		function catItem(id){
			$.ajax(itemHost+`/item/getData/${id}`)
			window.location.href="shop.html"
		}
		//点击其他分类的某一个二级菜单，会获取item表中item_cat_id为此id的商品，并显示在shop.html页面
		function otherItem(id){
			$.ajax(itemHost+`/item/getData/${id}`)
			window.location.href="shop.html"
		}
		//点击搜索框触发
		function searchItem(){
			let keyword = $("#search").val()
			$.ajax({
				type: "get",
				url: itemHost+"/item/search",
				data: {
					keyword:keyword
				},
				success: function(result){
					if(result.status==200){
						window.location.href = "shop.html"
					}
				}
			})
		}
		//退出登录
		function logout(){
			if(localStorage.getItem("accessToken") == null){
				alert("您还没有登录")
			}else{
				localStorage.removeItem("accessToken")
				localStorage.removeItem("refreshToken")
				sessionStorage.removeItem("userName")
				window.location.href = "index.html"
			}
		}
		/* 登录认证，如果没有登录，就不会跳转到account.html页面 */
		function accountAuth(){
			if(localStorage.getItem("accessToken")==null){
				alert("您还没有登录")
			}else{
				window.location.href = "account.html"
			}
		}
		/* 登录认证，如果没有登录，就不会跳转到cart.html页面 */
		function cartAuth(){
			if(localStorage.getItem("accessToken")==null){
				alert("您还没有登录")
			}else{
				window.location.href = "cart.html"
			}
		}
		<!-- 导航栏的JS-结束 -->
		var userHost = "http://localhost:3001/userservice"
		/* 点击注册按钮，执行此事件 */
		function register(){
			$.ajax({
				type:"post",
				url: userHost+"/user/register",
				data:$("#user_register").serialize(),
				// headers: {
				// 	"Authorization": "Bearer "+localStorage.getItem("accessToken")
				// },
				success:function(result){
					console.log(result);
					if(result.status == 200){
						alert("user表添加数据成功，注册成功");
						window.location.href="login.html"
					}else{
						alert(result.data)
					}
					console.log("成功返回");
				},
				error:function(result){
					console.log("失败"+result);
				}
			})
		}
		function showTips(spanID,msg){
			//首先要获得要操作元素 span
			var span = document.getElementById(spanID);
			span.innerHTML = msg;
		}
		/*
			校验用户名:
			1.事件: onblur  失去焦点
			2.函数: checkUsername()
			3.函数去显示校验结果
		*/
		function checkUsername(){
			//获取用户输入的内容
			var uValue = document.getElementById("username").value;
			//对输入的内容进行校验
			//获得要显示结果的span
			var span = document.getElementById("span_username");
			if(uValue.length < 2){
				//显示校验结果
				span.innerHTML = "<font color='red' size='2'>x,用户名太短</font>";
				return false;
			}else if(uValue.length > 10){
				span.innerHTML = "<font color='red' size='2'>x,用户名太长</font>";
				return false;
			}else{
				span.innerHTML = "<font color='green' size='2'>√,用户名可用</font>";
				return true;
			}
		}
		
		/*
		 密码校验
		 */
		function checkPassword(){
			//获取密码输入
			var uPass = document.getElementById("password").value;
			
			var span = document.getElementById("span_password");
			
			//对密码输入进行校验
			if(uPass.length < 6){
				span.innerHTML = "<font color='red' size='2'>X,密码太短</font>";
				return false;
			}else{
				span.innerHTML = "<font color='green' size='2'>√,密码可用</font>";
				return true;
			}
		}
		
		/*
		 确认密码校验
		 * */
		function checkRePassword(){
			//获取密码输入
			var uPass = document.getElementById("password").value;
			
			//获取确认密码输入
			var uRePass = document.getElementById("repassword").value;
			
			
			var span = document.getElementById("span_repassword");
			
			//对密码输入进行校验
			if(uPass != uRePass){
				span.innerHTML = "<font color='red' size='2'>X,两次密码不一致</font>";
				return false;
			}else{
				span.innerHTML = "";
				return true;
			}
		}
		/*校验手机号*/ 
		function checkPhone()
		{
		    var phone = document.getElementById("phone").value;
		    
		    // var flag = checkPhone(phone);
		    
		    // var span = document.getElementById("span_phone");
		    //对邮箱输入进行校验
		    if(!(/^1[3456789]d{9}$/.test(phone))){
		    	span.innerHTML = "<font color='green' size='2'>√,手机号可用</font>";
		    	return true;
		    }else{
		    	span.innerHTML = "<font color='red' size='2'>X,手机号码不正确</font>";
		    	return false;
		    }
		}
		
		/*
		 校验邮箱
		 * */
		function checkMail(){
			var umail = document.getElementById("email").value;
			
			var flag = checkEmail(umail);
			
			var span = document.getElementById("span_email");
			//对邮箱输入进行校验
			if(flag){
				span.innerHTML = "<font color='green' size='2'>√,邮箱可用</font>";
				return true;
			}else{
				span.innerHTML = "<font color='red' size='2'>X,邮箱格式有问题</font>";
				return false;
			}
		}
		
		function checkForm(){
			var flag = checkUsername() && checkPassword() && checkRePassword() && checkMail() && checkPhone();
			return flag;
		}
	</script>
</head>

<body>
    <!-- Header Section Start -->
    <div class="header section">

        <!-- Header Top Start -->
        <div class="header-top bg-name-primary">
            <div class="container">
                <div class="row align-items-center">

					<!-- Header Top Message Start -->
					<div class="col-12 col-lg-6">
					    <div class="header-top-msg-wrapper">
					        <a href="index.html" class="header-top-message">欢迎来到萌宠奇遇!</a>
					    </div>
					</div>
					<div class="col-12 col-lg-6">
					    <div class="header-top-settings">
							<a onclick="logout()" style="font-size: small; float: right; color: white;"> 退出登录 </a>
					        <a href="register.html" style="font-size: small; float: right; color: white;"> 注册&nbsp;&nbsp;|&nbsp;&nbsp; </a>
					        <a href="login.html" style="font-size: small; float: right; color: white;"> 登录&nbsp;&nbsp;|&nbsp;&nbsp;</a>
					    </div>
					</div>
					<!-- Header Top Message End -->

                </div>
            </div>
        </div>
        <!-- Header Top End -->

        <!-- Header Bottom Start -->
        <div class="header-bottom">
            <div class="header-sticky">
                <div class="container">
                    <div class="row align-items-center position-relative">

                        <!-- Header Logo Start -->
                        <div class="col-lg-3 col-md-4 col-6">
                            <div class="header-logo">
                                <a href="index.html"><img src="assets/images/logo/logo.png" alt="Site Logo" /></a>
                            </div>
                        </div>
                        <!-- Header Logo End -->

                        <!-- Header Menu Start -->
                        <div class="col-lg-6 d-none d-lg-block">
                            <div class="main-menu">
                                <ul>
                                    <li class="has-children">
                                        <a href="index.html">首页</a>
                                    </li>
                                    <li class="has-children position-static">
                                         <a href="#">萌宠商城</a>
                                        <ul class="mega-menu" id="itemCat">
                                            <li class="mega-menu-col">
                                                <h4 class="mega-menu-title">狗狗</h4>
                                                <ul class="m-b-n10" id="dog">
                                                    
                                                </ul>
                                            </li>
                                            <li class="mega-menu-col">
                                                <h4 class="mega-menu-title">猫咪</h4>
                                                <ul class="m-b-n10" id="cat">
                                                   
                                                </ul>
                                            </li>
                                            <li class="mega-menu-col">
                                                <h4 class="mega-menu-title">其他</h4>
                                                <ul class="m-b-n10" id="other">
                                                   
                                                </ul>
                                            </li>
                                            <li class="mega-menu-col">
                                                <div class="megamenu-image">
                                                    <a href="shop.html">
                                                        <img class="fit-image" src="assets/images/header/mega-menu.png" alt="Megamenu Image">
                                                    </a>
                                                </div>
                                            </li>
                                        </ul>
                                    </li>
                                    <li class="has-children">
                                        <a href="forum.html">萌宠论坛</a>
                                    </li>
                                    <li class="has-children">
                                        <a href="diary.html">萌宠日记</a>
                                    </li>
                                    <li><a href="login.html">登录</a></li>
                                    <li><a href="register.html">注册</a></li>
                                </ul>
                            </div>
                        </div>
                        <!-- Header Menu End -->

                        <!-- Header Action Start -->
                        <div class="col-lg-3 col-md-8 col-6">
                            <div class="header-actions">

                                <!-- Header Action Search Button Start -->
                                <div class="header-action-btn header-action-btn-search d-none d-md-flex">
                                    <div class="action-execute">
                                        <a class="action-search-open" href="javascript:void(0)"><i class="icon-magnifier icons"></i></a>
                                        <a class="action-search-close" href="javascript:void(0)"><i class="ti-close"></i></a>
                                    </div>
                                    <!-- Search Form and Button Start -->
                                    <form class="header-search-form" >
                                        <input type="text" class="header-search-input" placeholder="搜索商品" value="" id="search">
                                        <button class="header-search-button" onclick="searchItem()"><i class="icon-magnifier icons"></i></button>
                                    </form>
                                    <!-- Search Form and Button End -->
                                </div>
                                <!-- Header Action Search Button End -->

                                <!-- Header My Account Button Start -->
                                <a onclick="accountAuth()" class="header-action-btn header-action-btn-wishlist"">
                                    <i class="icon-user icons"></i>
                                </a>
                                <!-- Header My Account Button End -->

                                <!-- Header Action Button Start -->
                                <div class="header-action-btn header-action-btn-cart d-none d-sm-flex">
                                    <a onclick="cartAuth()" class="cart-visible">
                                        <i class="icon-handbag icons"><span style="font-size: medium;">&nbsp;购物车</span></i>
                                    </a>
                                </div>
                                <!-- Header Action Button End -->
                            </div>
                        </div>
                        <!-- Header Action End -->

                    </div>
                </div>
            </div>
        </div>
        <!-- Header Bottom End -->

    </div>
    <!-- Header Section End -->

    <!-- Breadcrumb Area Start -->
    <div class="section breadcrumb-area bg-name-bright">
        <div class="container">
            <div class="row">
                <div class="col-12 text-center">
                    <div class="breadcrumb-wrapper">
                        <h2 class="breadcrumb-title">创建账户</h2>
                        <ul>
                          <li><a href="index.html">主页</a></li>
                            <li>创建账户&nbsp;</li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Breadcrumb Area End -->

    <!-- Register Section Start -->
    <div class="section section-margin">
        <div class="container">
            <div class="row">
                <div class="col-lg-7 col-md-8 m-auto">
                    <div class="login-wrapper">

                        <!-- Register Title & Content Start -->
                        <div class="section-content text-center m-b-30">
                            <h2 class="title m-b-10">创建账户</h2>
                        </div>
                        <!-- Register Title & Content End -->

                        <!-- Form Action Start -->
                        <form action="#" method="post" id="user_register" onsubmit="return checkForm()">
                        
                            <!-- Input Name Start -->
                            <div class="single-input-item m-b-10">
                                <input type="text" placeholder="用户名" name="username" id="username" onfocus="showTips('span_username','用户名长度不能小于6')" onblur="checkUsername()" onkeyup="checkUsername()"/><span id="span_username"></span>
                            </div>
                            <!-- Input Name End -->
                        	
                        	<!-- 密码 -->
                        	
                        	<div class="single-input-item m-b-10">
                                <input type="password" name="password" placeholder="密码" id="password" onfocus="showTips('span_password','密码长度不能小于6')" onblur="checkPassword()" onkeyup="checkPassword()"/><span id="span_password"></span>
                            </div>
                        	
                        	<!-- 确认密码 -->
                        	
                        	<div class="single-input-item m-b-10">
                                <input type="password" name="repassword" placeholder="确认密码" id="repassword" onfocus="showTips('span_repassword','两次密码必须一致')" onblur="checkRePassword()" onkeyup="checkRePassword()"/><span id="span_repassword"></span>
                            </div>
                        	
                        	<!-- 手机号 -->
                        	
                        	<div class="single-input-item m-b-10">
                                <input type="text" name="phone" placeholder="手机号" id="text" onfocus="showTips('span_phone','请输入十一位手机号码!')" onblur="checkPhone" onkeyup="checkPhone()"/><span id="span_phone"></span>
                            </div>
                        
                            <!-- Input Email Start -->
                            <div class="single-input-item m-b-10">
                                <input type="email" name="email" placeholder="邮箱" id="email" onfocus="showTips('span_email','邮箱格式必须正确')" onblur="checkMail()" onkeyup="checkMail()"/><span id="span_email"></span>
                            </div>
                            <!-- Input Email End -->
                        
                            <!-- Button/Forget Password Start -->
                            <div class="single-input-item">
                                <div class="login-reg-form-meta m-b-n15">
                                    <button type="button" class="btn btn btn-gray-deep btn-hover-primary m-b-15" onclick="register();">注册</button>
                        			<button type="reset" class="btn btn btn-gray-deep btn-hover-primary m-b-15">重置</button>
                                </div>
                            </div>
                            <!-- Button/Forget Password End -->
                        	<div class="lost-password">
                        	    <a href="login.html">已有账号?请登录</a>
                        	</div>
                        </form>
                        <!-- Form Action End -->

                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Register Section End -->

    <!-- Footer Section Start -->
    <footer class="section footer-section">
        <!-- Footer Top Start -->
        <div class="footer-top bg-name-bright section-padding">
            <div class="container">
                <div class="row m-b-n40">
                    <div class="col-12 col-sm-6 col-lg-3 m-b-40" data-aos="fade-up" data-aos-duration="1000">
                        <div class="single-footer-widget">
                            <h1 class="widget-title">关于我们</h1>
                            <p class="desc-content">然后疼痛就会停止，疼痛就会受到折磨。</p>
                            <!-- Soclial Link Start -->
                            <div class="widget-social justify-content-start m-b-n10">
                                <a title="Twitter" href="#/"><i class="icon-social-twitter"></i></a>
                                <a title="Instagram" href="#/"><i class="icon-social-instagram"></i></a>
                                <a title="Linkedin" href="#/"><i class="icon-social-linkedin"></i></a>
                                <a title="Skype" href="#/"><i class="icon-social-skype"></i></a>
                                <a title="Dribble" href="#/"><i class="icon-social-dribbble"></i></a>
                            </div>
                            <!-- Social Link End -->
                        </div>
                    </div>
                    <div class="col-12 col-sm-6 col-lg-3 m-b-40" data-aos="fade-up" data-aos-duration="1200">
                        <div class="single-footer-widget">
                            <h2 class="widget-title">有用的链接</h2>
                            <ul class="widget-list">
                              <li><a href="wishlist.html">帮助和联系我们</a></li>
                                <li><a href="contact.html">退货和退款</a></li>
                                <li><a href="contact.html">线上商店</a></li>
                                <li><a href="contact.html">条款与条件</a></li>
                            </ul>
                        </div>
                    </div>
                    <div class="col-12 col-sm-6 col-lg-3 m-b-40" data-aos="fade-up" data-aos-duration="1400">
                        <div class="single-footer-widget">
                            <h2 class="widget-title">帮助</h2>
                            <ul class="widget-list">
                              <li><a href="wishlist.html">愿望清单</a></li>
                                <li><a href="contact.html">定价计划</a></li>
                                <li><a href="contact.html">物流跟踪</a></li>
                                <li><a href="contact.html">退换商品</a></li>
                            </ul>
                        </div>
                    </div>
                    <div class="col-12 col-sm-6 col-lg-3 m-b-40" data-aos="fade-up" data-aos-duration="1600">
                        <div class="single-footer-widget">
                            <h2 class="widget-title">发送时事通讯</h2>
                            <div class="widget-body">
                              <p class="desc-content m-b-20">订阅我们的时事通讯，首次购买可享受10%的折扣。</p>
                                <!-- Newsletter Form Start -->
                                <div class="newsletter-form-wrap p-t-5">
                                    <form id="mc-form" class="mc-form">
                                        <input type="email" id="mc-email" class="form-control email-box" placeholder="demo@example.com" name="EMAIL">
                                        <button id="mc-submit" class="newsletter-btn" type="submit">发送</button>
                                    </form>
                                    <!-- mailchimp-alerts Start -->
                                    <div class="mailchimp-alerts text-centre">
                                        <div class="mailchimp-submitting"></div><!-- mailchimp-submitting end -->
                                        <div class="mailchimp-success text-success"></div><!-- mailchimp-success end -->
                                        <div class="mailchimp-error text-danger"></div><!-- mailchimp-error end -->
                                    </div>
                                    <!-- mailchimp-alerts end -->
                                </div>
                                <!-- Newsletter Form End -->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- Footer Top End -->
    </footer>
    <!-- Footer Section End -->

    <script src="assets/js/vendor.min.js"></script>
    <script src="assets/js/plugins.min.js"></script>

    <!--Main JS-->
    <script src="assets/js/main.js"></script>
</body>

</html>